
using Elastic.Clients.Elasticsearch;
using Elasticsearch.Extensions;
using Elasticsearch.Service;

namespace Elasticsearch
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var builder = WebApplication.CreateBuilder(args);

            // Add services to the container.
            builder.Services.AddControllers();
            // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
            builder.Services.AddEndpointsApiExplorer();
            builder.Services.AddSwaggerGen();
            var config = builder.Services.BuildServiceProvider().GetService<IConfiguration>();
            // 注册 Elasticsearch 客户端
            //builder.Services.AddSingleton(provider =>
            //{
            //    var settings = new ElasticsearchClientSettings(new Uri("http://localhost:9200")); // 设置默认索引
            //    return new ElasticsearchClient(settings);
            //});
            builder.Services.AddTransient<IIndexService, IndexService>();
            builder.Services.AddTransient<IUserService, UserService>();
            builder.Services.AddElasticsearchServices(config);

            var app = builder.Build();

            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseSwagger();
                app.UseSwaggerUI();
            }

            app.UseHttpsRedirection();

            app.UseAuthorization();


            app.MapControllers();

            app.Run();
        }
    }
}
